Tester - Unit Testing for Php
Unit testing library.
UNDER DEVELOPMENT: v0.3 is pretty functional, but this v1.0 is under development and not ready to use.
Documentation
- Install:
composer require taeluf/tester v1.0.x-dev
- Getting Started (below)
- Usage
- Assertions
- Helpers - Overview of Helper objects for databasing, http requests, and more.
- Configure
-
CLI - (or use
vendor/bin/phptest help
) - Example - This library's tests
- Alternatives
- Development
Getting Started
Use defaults, or Configure as needed.
Follow steps below, or see an example.
Create a test
-
vendor/bin/phptest create-test
- Follow the prompts, which will create a new test file
- Setup your test in the
testMain()
method (or create new testWhatever() methods)
A test is a single method within a class implementing the Tlf\Tester interface, prefixed with test
. Alternatively, use $tester->add_test($callable)
in your test/bootstrap.php
file.
For a test to pass, all assertions in the test must pass. If any assertions fail, or if there are no assertions, then the test fails.
Tips
- Most accessible methods on
$this
are assertions. -
$this
has multiple helper objects as properties. Trydb
,server
,exceptions
, andutility
Run your tests
-
vendor/bin/phptest
: Run all tests -
vendor/bin/phptest -test TestName
: Run tests with the given TestName (Supports multiple -test flags) -
vendor/bin/phptest -class ClassBaseName
: Run all tests for a class. (Supports multiple -class flags)
Screenshots & Examples
Also see the CLI documentation.
CLI Help Menu
... include image here ...
Test Results
... test results ...
Example Test class
<?php
namespace Tlf\Tester\Test\Runner;
class NestedTest extends \Tlf\Tester {
/** called before tests are run */
public function prepare(){}
/** Test methods must prefix with `test` */
public function testAnything(){
$this->compare(true,true);
}
}